package com.xw.service.xw.cfOrder;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xw.dao.DaoSupport;
import com.xw.entity.Page;
import com.xw.util.PageData;

/**
 * 类名称: CfCardService
 * 类描述: 处方单业务类
 * @author : gce
 * @date   : 2017-12-1
 */
@Service("cfOrderService")
public class CfOrderService {
	
	@Resource(name = "daoSupport")
	private DaoSupport dao;
	
	//添加处方单,返回处方单id
	public long save(PageData pd) throws Exception {
		dao.save("CfOrderMapper.save", pd);
		Page page = new Page();
		page.setPd(pd);
		List<PageData> list = this.listByPid(page);
		return (long) list.get(0).get("id");
	}
	
	//添加处方单已开药品
	/**
	 * 添加处方单已开药品  #{cfdId}
	 * @param pd
	 * @throws Exception
	 * @return: void
	 * @author: gce
	 * @date  : 2017-12-11
	 */
	public void saveYkcfyp(PageData pd) throws Exception {
		dao.save("CfOrderMapper.saveYkcfyp", pd);
	}
	
	//查询库存
	/**
	 * 查询库存 #{ypId}  #{mzId}
	 * @param pd
	 * @throws Exception
	 * @return: PageData
	 * @author: gce
	 * @date  : 2017-12-11
	 */
	public PageData findKc(PageData pd) throws Exception{
		return (PageData)dao.findForObject("CfOrderMapper.findKc", pd);
	}
	
	//修改库存
	/**
	 * 修改库存 #{ypid} #{mzid}
	 * @param pd
	 * @throws Exception
	 * @return: void
	 * @author: gce
	 * @date  : 2017-12-11
	 */
	public void updateKc(PageData pd) throws Exception{
		dao.update("CfOrderMapper.updateKc", pd);
	}
	
	//根据患者id,查询处方单列表
	/**
	 * 根据患者id,查询处方单列表  #{pd.hzId}
	 * @param pd
	 * @throws Exception
	 * @return: PageData
	 * @author: gce
	 * @date  : 2017-12-11
	 */
/*	public List<PageData> findById(PageData pd) throws Exception {
		return (List<PageData>) dao.findForObject("CfOrderMapper.byPidlistPage", pd);
	}*/
	
	//根据处方单id,查询处方单详情#{id}
	/**
	 * 根据处方单id,查询处方单详情#{id}
	 * @param pd
	 * @throws Exception
	 * @return: PageData
	 * @author: gce
	 * @date  : 2017-12-15
	 */
	public PageData findByCfId(PageData pd) throws Exception {
		return (PageData) dao.findForObject("CfOrderMapper.findByCfId", pd);
	}
	
	//删除处方单（根据处方单ID）
	public int deleteByCaseId(PageData pd) throws Exception {
		return (int)dao.delete("CfOrderMapper.deleteByCaseId", pd);
	}
	
	/**
	 * 查询处方单列表，根据患者ID
	 * @param page
	 * @throws Exception
	 * @return: List<PageData>
	 * @author: gce
	 * @date  : 2017-12-6
	 */
	public List<PageData> listByPid(Page page) throws Exception {
		return (List<PageData>) dao.findForList("CfOrderMapper.byPidlistPage", page);
	}
	
	/**
	 * 查询处方单列表，根据处方单ID
	 * @param page
	 * @throws Exception
	 * @return: List<PageData>
	 * @author: gce
	 * @date  : 2017-12-15
	 */
	public List<PageData> listByCid(Page page) throws Exception {
		return (List<PageData>) dao.findForList("CfOrderMapper.byCidlistPage", page);
	}
	
	/**
	 * 查询匹配条件的所有患者的最后一次病历
	 * @param page
	 * @throws Exception
	 * @return: List<PageData>
	 * @author: gce
	 * @date  : 2017-12-6
	 */
	public List<PageData> findCase(Page page) throws Exception {
		return (List<PageData>) dao.findForList("CfOrderMapper.findCaselistPage", page);
	}
	
	/**
	 * 查询药品（根据门诊ID、或药品编码、或药品名称、或药品拼音码）
	 * @param page
	 * @throws Exception
	 * @return: List<PageData>
	 * @author: gce
	 * @date  : 2017-12-12
	 */
	public List<PageData> yplistPage(Page page) throws Exception{
		return (List<PageData>) dao.findForList("CfOrderMapper.yplistPage", page);
	}
	
	/**
	 * 查询药品（根据处方单ID）
	 * @param page
	 * @throws Exception
	 * @return: List<PageData>
	 * @author: gce
	 * @date  : 2017-12-12
	 */
	public List<PageData> ykyplistPage(Page page) throws Exception{
		return (List<PageData>) dao.findForList("CfOrderMapper.ykyplistPage", page);
	}
	
	//删除处方单（修改状态）
	public int delete(PageData pd) throws Exception {
		 return (int)dao.delete("CfOrderMapper.delete", pd) ;
	}
	
}
